<template>
  <div class="border-b-2 border-b-slate-100 p-4 lg:p-8 mb-4 lg:mb-8">
    <h1 class="text-2xl lg:text-3xl font-bold mb-4 lg:mb-8 text-center">{{ newData.title }}</h1>
    <div class="flex justify-center items-center gap-16 text-gray-600">
      <p>时间：{{ newData.update_time }}</p>
      <p>浏览次数：{{ newData.view_count }}</p>
    </div>
  </div>
  <div v-html="newData.content"></div>
</template>

<script setup>
const route = useRoute();
const { type, n_id } = route.params;
const apiUrl = {
  list: "newDetails",
  company: "companyDetails",
  exhibition: "exhibitionDetails",
};

const { data: result } = await useAsyncData(`${apiUrl[type]}/${n_id}`, async () => {
  const { data } = await useFetch(`/api/news/${apiUrl[type]}`, { params: { n_id } });
  return data.value;
});
console.log(result.value);
const newData = ref({});
if (result.value.code === 1) {
  newData.value = result.value.data;
}
</script>
<style scoped lang="scss"></style>
